/*
 * @(#)IITransformer.java
 * Date 2013-08-25
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.hl7v3common.transformer;

import javax.enterprise.context.ApplicationScoped;

import org.hl7.v3.II;

import us.hornerscorners.lamppost.hl7v3common.constant.Interaction;

import us.hornerscorners.lamppost.model.common.InstanceIdentifier;

import us.hornerscorners.lamppost.transformer.AbstractTransformer;

import us.hornerscorners.lamppost.utils.UUIDUtils;


/**
 *
 * @author jim
 */
@ApplicationScoped
public class IITransformer extends AbstractTransformer<InstanceIdentifier, II> {

    /**
     * Constructs ...
     *
     */
    public IITransformer() {
        super();
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public II createNullFlavorII() {

        II result = new II();

        result.getNullFlavor().add("NA");

        return result;
    }

    /**
     * Method description
     *
     *
     * @return
     */
    public II createRandomII() {

        return transform(null, UUIDUtils.generate());
    }

    /**
     * Method description
     *
     *
     * @param id
     *
     * @return
     */
    @Override
    public II transform(InstanceIdentifier id) {

        II result = new II();

        result.setAssigningAuthorityName(id.getAssigningAuthorityName());
        result.setDisplayable(id.getDisplayable());
        result.setExtension(id.getExtension());
        result.setRoot(id.getRoot());

        return result;
    }

    /**
     * Method description
     *
     *
     * @param interaction
     *
     * @return
     */
    public II transform(Interaction interaction) {

        return transform(interaction.getCode(), Interaction.Root.getCode());
    }

    /**
     * Method description
     *
     *
     * @param extension
     * @param root
     *
     * @return
     */
    public II transform(String extension, String root) {

        II result = new II();

        result.setExtension(extension);
        result.setRoot(root);

        return result;
    }
}
